﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace BarManager.Core.Entity
{
    [DataContract]
    public class PromocionDetalle
    {
        [Required]
        [DataMember]
        public int ProductoId { get; set; }
        
        [DataMember]
        public Guid Guid { get; set; }

        [Required]
        [DataMember]
        public int PromocionId { get; set; }

        [Required]
        [Range(typeof(Int32), "1", "20")]
        [DataMember]
        public int Cantidad { get; set; }

        [DataType(DataType.Currency)]
        [DataMember]
        public decimal SubTotal
        {
            get
            {
                if (Producto != null && Producto.PrecioVenta.HasValue) 
                    return Producto.PrecioVenta.Value * Cantidad;
                return 0;
            }
        }

        [DataMember]
        public virtual Producto Producto { get; set; }

        [DataMember]
        public virtual Promocion Promocion { get; set; }

        public PromocionDetalle()
        {
            Guid = Guid.NewGuid();
        }
    }
}
